BI.BasicTreeNode = BI.inherit(BI.NodeButton, {
    _defaultConfig: function (props) {
        var conf = BI.BasicTreeNode.superclass._defaultConfig.apply(this, arguments);
        return BI.extend(conf, {
            baseCls: (conf.baseCls || "") + " bi-tree-node " + (props.selectable ? "bi-list-item-active" : "bi-list-item"),
            id: "",
            pId: "",
            open: false,
            height: 24,
            readonly: true,
            isFirstNode: false,
            isLastNode: false,
            switcherIcon: {},
            selectable: true,
            disabled: false, // disabled不会影响展开收起功能
        });
    },

    render: function () {
        var self = this, o = this.options;

        const checkbox = {
            type: "bi.tree_node_switcher",
            __ref: function (_ref) {
                self.switcher = _ref;
            },
            iconHeight: o.height,
            iconWidth: o.iconWrapperWidth || o.height,
            open: o.open,
            isFirstNode: o.isFirstNode,
            isLastNode: o.isLastNode,
            layer: o.layer,
            ...o.switcherIcon,
            stopPropagation: o.selectable,
            mounted: function () {
                this.setEnable(true);
            },
            listeners: [
                {
                    eventName: "EVENT_CHANGE",
                    action: () => {
                        if (!this.isEnabled() || o.selectable) {
                            this.isOpened() ? this.triggerCollapse() : this.triggerExpand();
                        }
                    }
                }
            ]
        };

        return {
            type: "bi.vertical_adapt",
            columnSize: [o.iconWrapperWidth || o.height, "fill"],
            items: [
                {
                    el: checkbox,
                    lgap: o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2,  //  偏移公式为每一层的偏移量为节点高度的一半
                }, {
                    el: {
                        type: "bi.label",
                        ref: function (_ref) {
                            self.text = _ref;
                        },
                        textAlign: "left",
                        whiteSpace: "nowrap",
                        textHeight: o.height,
                        height: o.height,
                        hgap: o.hgap || o.textHgap,
                        vgap: o.textVgap,
                        lgap: o.textLgap,
                        rgap: o.textRgap,
                        text: o.text,
                        value: o.value,
                        keyword: o.keyword,
                        py: o.py
                    }
                }
            ]
        };
    },

    doRedMark: function () {
        this.text.doRedMark.apply(this.text, arguments);
    },

    unRedMark: function () {
        this.text.unRedMark.apply(this.text, arguments);
    },

    doClick: function () {
        if (this.options.selectable) {
            return;
        }
        BI.BasicTreeNode.superclass.doClick.apply(this, arguments);
    },

    setOpened: function (v) {
        BI.BasicTreeNode.superclass.setOpened.apply(this, arguments);
        this.switcher.setOpened(v);
    },

    setValue: function () {
        BI.BasicTreeNode.superclass.setValue.apply(this, arguments);
    }
});

BI.shortcut("bi.tree_node", BI.BasicTreeNode);
